package com.hzit.page.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
import org.springframework.session.web.http.CookieSerializer;
import org.springframework.session.web.http.DefaultCookieSerializer;

/**
 * 类名：
 * 作者：WF
 * 功能：
 */
@Configuration
@EnableRedisHttpSession
public class SpringSessionConfig {
	//1. 对redis进行序列化
	@Bean
	public RedisSerializer<Object> springSessionDefaultRedisSerializer() {
		return new GenericJackson2JsonRedisSerializer();
	}
	//2. 自定义cookie信息
	@Bean
	public CookieSerializer cookieSerializer() {
		DefaultCookieSerializer serializer = new DefaultCookieSerializer();
		serializer.setCookieName("HZIT_COOKIE");
		serializer.setDomainName("hzit.com"); //对hzit.com及其下的子域名都会起作用！
		return serializer;
	}
}
